.PHONY: all build run go-tool clean project help

BINARY:="go-gin-demo"

all: go-tool build

build:
	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${BINARY}

run:
	@go run ./main.go conf/config.yaml

go-tool:
	go fmt ./
	go vet ./
	#golangci-lint run --print-resources-usage

clean:
	@if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi

project:
	@mkdir ../${name}
	@cp -r * ../${name}
	@sed -i "" "s/go-gin-demo/${name}/g" `grep -rl go-gin-demo ../${name}`
	@rm -rf ../${name}/.git
	@sed -i "" "1 s/project //g" ../${name}/Makefile
	@sed -i "" "21,29d;36d" ../${name}/Makefile
	@echo "New project had been created: `(cd ../${name} && pwd)`"

help:
	@echo "make - 格式化 Go 代码，并编译生成二进制文件"
	@echo "make build - 编译 Go 代码，生成二进制文件"
	@echo "make run - 直接运行 Go 代码"
	@echo "make clean - 移除二进制文件和 vim swap 文件"
	@echo "make go-tool - 格式化 Go 代码（运行 Go 工具 fmt 和 vet）"
	@echo "make project name=*** - 根据当前脚手架生成新项目"